package com.zx.kitchen.index.common.mvp.presenter;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.zx.kitchen.index.common.entity.GoodDetailListBean;
import com.zx.kitchen.index.common.mvp.OnResultListener;
import com.zx.kitchen.index.common.mvp.model.PurchaseGoodsDetailModelImpl;
import com.zx.kitchen.index.common.mvp.view.GoodsDetailView;

/**
 * Created by Administrator on 2017/3/20.
 */

public class PurchaseGoodsDetailPresenter implements OnResultListener {
    private PurchaseGoodsDetailModelImpl purchaseGoodsDetailModel;
    private GoodsDetailView goodsDetailView;
    private Context context;

    public PurchaseGoodsDetailPresenter(Context context, GoodsDetailView goodsDetailView) {
        this.context = context;
        this.goodsDetailView = goodsDetailView;
        purchaseGoodsDetailModel = new PurchaseGoodsDetailModelImpl();
    }

    public void getFromNet(String start_time, String end_time, String goods_id, String type) {
        purchaseGoodsDetailModel.getFromNet(0, context, start_time, end_time, goods_id, type, this, null);
    }

    @Override
    public void onSuccess(int requestCode, String str) {
        GoodDetailListBean goodDetailListBean = JSON.parseObject(str, new TypeReference<GoodDetailListBean>() {
        });
        goodsDetailView.onSuccess(goodDetailListBean);
    }

    @Override
    public void onFailure(int requestCode, String str) {
        goodsDetailView.onFail(str);
    }
}
